home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / java / magic oracle / mainframebeaninfo.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  1.8 KB  |  65 lines

  1. import java.beans.*;
  2. import java.lang.reflect.*;
  3.  
  4. public class MainFrameBeanInfo extends SimpleBeanInfo 
  5. {
  6.     /**
  7.      * A method descriptor used by AppleScript for Java's introspector to generate the aete
  8.      * This descriptor describes the parameters and method to be published in the aete and
  9.      * overrides the default generated values
  10.      */
  11.     public MethodDescriptor[] getMethodDescriptors()    
  12.     {
  13.         MethodDescriptor md[] = new MethodDescriptor[1];    // the method descriptor provides 
  14.                                                             // extra information to the introspector
  15.         try
  16.         {
  17.             /** Creating a parameter descriptor allows you to specify a formal name in the terminology
  18.               * for the paramter(s) of a method. In this instance, you will be able to write:
  19.               *
  20.               * ask Oracle of <object> question "Whatever"
  21.               * 
  22.               * instead of:
  23.               * 
  24.               *  ask Oracle of <object> parameters { "Whatever" }
  25.               * 
  26.               */
  27.             
  28.             ParameterDescriptor[] pd = new ParameterDescriptor[1];
  29.             pd[0] = new ParameterDescriptor();
  30.             pd[0].setShortDescription( "Question to ask of the oracle." );
  31.             pd[0].setName( "question" );
  32.             
  33.             md[0] = new MethodDescriptor( getMethod( MainFrame.class, "askMystic" ), pd) ;
  34.             md[0].setShortDescription( "Ask the Oracle a yes/no question and receive a response." );
  35.             
  36.             return md;
  37.         }
  38.         catch ( IntrospectionException e )
  39.         {
  40.             e.printStackTrace();
  41.         }
  42.         return null;
  43.     }
  44.     
  45.     /**
  46.      * getMethod is called by the introspector to return a list of methods in the class
  47.      */
  48.     Method getMethod( Class c, String methodName )    throws IntrospectionException
  49.     {
  50.         Method methods[] = c.getMethods();
  51.         
  52.         for ( int i = 0; i < methods.length; i++ )
  53.         {
  54.             if ( methods[i].getName().equals( methodName )) 
  55.             {
  56.                 return methods[i];
  57.             }
  58.         }
  59.         throw new IntrospectionException( "No such method \"" + methodName + "\"" );
  60.     }
  61.     
  62.             
  63.             
  64. }
  65.